package p2p.utils
{
	public class MessageUtils
	{
		public static const COMMON_MSG_COLOR:String = "#CC9900";
		public static const PRIVATE_MSG_COLOR:String = "#993300";
		public static const PUBLIC_MSG_COLOR:String = "#336600";
		
		public static function getWelcomeMessage(groupName:String) : String
		{
			return "<FONT color='" + COMMON_MSG_COLOR + "'><B><U>Welcome to Video Chat in group \"" + groupName + "\"!</U></B></FONT>";
		}
		
		public static function getDisconnectionMessage(peerName:String) : String
		{
			return "<FONT color='" + COMMON_MSG_COLOR + "'><I>" + peerName + " has <U>disconnected</U> from the chat :(</I></FONT>";
		}
		
		public static function getConnectionMessage(peerName:String) : String
		{
			return "<FONT color='" + COMMON_MSG_COLOR + "'><I>" + peerName + " has <U>connected</U> to the chat :)</I></FONT>";
		}
		
		public static function getPrivateRecieveMessage(yourName:String, text:String) : String
		{
			return '<font color="' + PRIVATE_MSG_COLOR + '"><b>' + yourName + ' said to YOU</b>: "' + text + '"</font>';
		}
		
		public static function getPrivateSendMessage(clientName:String, text:String) : String
		{
			return '<font color="' + PRIVATE_MSG_COLOR + '"><b>You said to ' + clientName + '</b>: "' + text + '"</font>';
		}
		
		public static function getPublicRecieveMessage(yourName:String, text:String) : String
		{
			return '<font color="' + PUBLIC_MSG_COLOR + '"><b>' + yourName + ' said to ALL</b>: "' + text + '"</font>';
		}
		
		public static function getPublicSendMessage(text:String) : String
		{
			return '<font color="' + PUBLIC_MSG_COLOR + '"><b>You said to ALL</b>: "' + text + '"</font>';
		}
		
		public static function getFileSendMessage(fileName:String, size:Number) : String
		{
			return '<font color="' + PUBLIC_MSG_COLOR + 
					'"><b>You sent file to ALL</b>: "' + fileName + 
					',<i> size: </i>' + readablizeBytes(size) + '"</font>';
		}
		
		public static function getFileRecieveMessage(yourName:String, fileName:String, size:Number) : String
		{
			return	'<font color="' + PUBLIC_MSG_COLOR + 
					'"><b>' +  yourName + 
					' sent file to ALL</b>: "' + fileName  + 
					',<i> size: </i>: ' + readablizeBytes(size) + '"</font>';
		}
		
		public static function getConfirmationDialogMessage( senderName:String, filename:String, size:Number):String 
		{
			return	senderName + " has sent file '" + 
					filename + 	"'." +
					"\n(size:" + readablizeBytes(size) + ")" + 
					"\nDo you want to receive it?";
			
		}
		
		private static function readablizeBytes(bytes:uint):String 
		{
			var s:Array = ['bytes', 'kb', 'MB', 'GB', 'TB', 'PB'];
			var e:Number = Math.floor( Math.log(bytes) / Math.log(1024) );
		
			return ( bytes / Math.pow(1024, Math.floor(e))).toFixed(2) + " " + s[e];

		}
	}
}